﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Manage_BidStatus : System.Web.UI.Page , IAccess
{
    string format = "当前总企业数 {0} 家，总产品数 {1} 个；已报价企业 {2} 家，已报价产品 {3} 个；已报价且确认企业 {4} 家，已报价且确认产品 {5} 个；未确认企业 {6} 家，未确认产品 {7} 个。";
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentAccount.CheckSessionTimeOut(this);
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        GetCount();
        int totalrecord;
        string strWhere = " where 1=1 ";
        if (!string.IsNullOrEmpty(txtCompanyName.Text.Trim()))
        {
            strWhere += string.Format(@" and CompanyName_Tb like '%{0}%' ", txtCompanyName.Text.Trim());
        }
        switch (ddlStatus.SelectedValue)
        {
            case "0":
                strWhere += " and EncryptPrice is null ";
                break;
            case "1":
                strWhere += " and EncryptPrice is not null ";
                break;
            case "2":
                strWhere += " and ConfirmStatus = 1 ";
                break;
        }
        var datasource = BLL_Factory.IBLL_Manage.GetBidStatusNew(strWhere, pager1.CurrentPage, pager1.PageSize, out totalrecord);
        pager1.RecordCount = totalrecord;
        gv2.DataSource = datasource;
        gv2.DataBind();

    }

    protected void btnQeury_Click(object sender, EventArgs e)
    {
        pager1.CurrentPage = 1;
        BindData();
    }
    protected void pager1_PageChanging(object sender, HZ.Web.PageChaningEventArgs e)
    {
        BindData();

    }

    private void GetCount()
    {
        /*写法太复杂 by yjx 2016年8月15日 16:30:25
        int bidcompanycount = BLL_Factory.IBLL_Common.GetBidCompanyCount();
        int allcompanycount = BLL_Factory.IBLL_Common.GetAllCompnayCount();
        int allgoodscount = BLL_Factory.IBLL_Common.GetAllGoodsCount(CurrentAccount.ProjectId);
        int bidgoodscount = BLL_Factory.IBLL_Common.GetBidGoodsCount(CurrentAccount.ProjectId);
         */
        DataTable dtcount = BLL_Factory.IBLL_Common.GetBidCount();
        if (dtcount.Rows.Count > 0)
        {
            int allcompanycount = Convert.ToInt32(dtcount.Rows[0]["企业总数"]);
            int allgoodscount = Convert.ToInt32(dtcount.Rows[0]["产品总数"]);
            int bidgoodscountall = 0;
            if (!string.IsNullOrEmpty(dtcount.Rows[0]["已报价产品数"].ToString()))
            {
                bidgoodscountall = Convert.ToInt32(dtcount.Rows[0]["已报价产品数"]);
            }
            int bidgoodscount = 0;
            if (!string.IsNullOrEmpty(dtcount.Rows[0]["已报价且确认产品数"].ToString()))
            {
                bidgoodscount = Convert.ToInt32(dtcount.Rows[0]["已报价且确认产品数"]);
            }
            int bidcompanycountall = 0;
            if (!string.IsNullOrEmpty(dtcount.Rows[0]["已报价企业数"].ToString()))
            {
                bidcompanycountall = Convert.ToInt32(dtcount.Rows[0]["已报价企业数"]);
            }
            int bidcompanycount = 0;
            if (!string.IsNullOrEmpty(dtcount.Rows[0]["已报价且确认企业数"].ToString()))
            {
                bidcompanycount = Convert.ToInt32(dtcount.Rows[0]["已报价且确认企业数"]);
            }
            string r = string.Format(format, allcompanycount, allgoodscount, bidcompanycountall, bidgoodscountall, bidcompanycount, bidgoodscount, allcompanycount - bidcompanycount, allgoodscount - bidgoodscount);
            ltlinfo.Text = r;
        }
    }
    #region IAccess Members

    IList<EnumAccess> IAccess.AccessList
    {
        get
        {
            var list = new List<EnumAccess>();
            list.Add(EnumAccess.Manage);
            return list;
        }

    }

    #endregion

    protected void btnNotBid_Click(object sender, EventArgs e)
    {
        var dt = HZ.Data.DbHelperFactory.Create().ExecuteTable(" SELECT DISTINCT ProductId 竞价组号,ProductCode 招标编码,BidMuLuCode 招标通用名,DirectoryCode 招标剂型,BidTableCode 招标规格  FROM View_BidPrice WHERE ProductId not IN (SELECT ProductId FROM dbo.TB_GoodsInfo WHERE Companyid_SC IN  (SELECT CompanyId FROM dbo.TB_Company_Project_Switch WHERE ConfirmStatus = 1))");
        HZ.Web.WebUtil.ExportToExcel(dt, "NotBidlist.xls");
    }
   
}
